package com.iter.devbox.jcaptcha;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

public class MyJcaptcha {

	public static final int WIDTH = 120;
	
    public static final int HEIGHT = 50;
    
    public void drawImageName (String name) throws FileNotFoundException, IOException {
    	// 创建缓存
        BufferedImage bufferedImage = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
        // 获得画布
        Graphics g = bufferedImage.getGraphics();
        // 设置颜色
        g.setColor(Color.WHITE);
        // 填充区域
        g.fillRect(0, 0, WIDTH, HEIGHT);
        // 设置边框颜色
        g.setColor(Color.RED);
        // 边框区域
        g.drawRect(1, 1, WIDTH - 2, HEIGHT - 2);
        // 设置颜色
        g.setColor(Color.RED);
        // 设置字体
        g.setFont(new Font("宋体", Font.BOLD, 35));
        // 画数据
        g.drawString(name, 3, 35);
        // 输出图片
        ImageIO.write(bufferedImage, "jpg", new FileOutputStream(new File("c:/aa.jpg")));
    }

	public static void main(String[] args) throws Throwable {
		MyJcaptcha myJcaptcha = new MyJcaptcha();
		myJcaptcha.drawImageName("杨利军");
	}
}
